import validate, { validators } from 'validate.js';

const REGEX_MOBILE = /^1\d{10}/;
const REGEX_STRICT_NUMBER = /^(0|[1-9]\d*)(\.\d+)?$/;

/* eslint-disable consistent-return */

validators.mobile = (value, options) => {
  if (validate.isEmpty(value) && options) {
    return;
  }

  if (!REGEX_MOBILE.test(value)) {
    return false;
  }
};

validators.strictNumber = (value, options) => {
  if (validate.isEmpty(value) && options) {
    return;
  }

  if (!REGEX_STRICT_NUMBER.test(value)) {
    return false;
  }
};

/* eslint-enable consistent-return */

export default validate;
